package com.evo.chat.admin.service.impl;

import com.evo.chat.admin.domain.Reply;
import com.evo.chat.admin.repository.ReplyRepository;
import com.evo.chat.admin.service.AdminReplyService;
import com.evo.chat.common.Result;
import com.evo.chat.common.utils.ResultUtil;
import com.evo.chat.web.domain.Words;
import com.evo.chat.web.repository.WordsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author luwenzheng
 * date 2020-02-06
 */
@Service
public class AdminReplyServiceImpl implements AdminReplyService {

    private final Logger logger = LoggerFactory.getLogger(AdminReplyServiceImpl.class);

    @Autowired
    WordsRepository wordsRepository;

    @Autowired
    ReplyRepository replyRepository;

    @Override
    public Result createReply(Integer wordId, String replyName, String content) {
        Reply replyModel = new Reply();
        replyModel.setrContent(content);
        replyModel.setrName(replyName);
        Optional<Words> byId = wordsRepository.findById(wordId);
        replyModel.setWords(byId.get());
        replyRepository.save(replyModel);
        return ResultUtil.success();
    }

}
